package com.qinge.blog.controller;

import com.github.pagehelper.PageInfo;
import com.qinge.blog.entity.BlogImage;
import com.qinge.blog.service.*;
import com.qinge.blog.utils.result.JsonResult;
import com.qinge.blog.utils.result.ResultTool;
import com.qinge.blog.vo.BaseIdReqVO;
import com.qinge.blog.vo.paging.PagingReqVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author QDW
 * @date 2022/05/13 21:07
 */
@RestController
@RequestMapping("/blog/api/image")
public class BlogImageController {


    @Resource
    private BlogImageService blogImageService;

    @PostMapping("/add")
    public JsonResult add(BlogImage blogImage) {
        blogImageService.add(blogImage);

        return ResultTool.success();
    }

    @PostMapping("/remove")
    public JsonResult remove(BaseIdReqVO idReqVO) {
        blogImageService.removeById(idReqVO.getId());

        return ResultTool.success();
    }

    @PostMapping("/update")
    public JsonResult update(BlogImage blogImage) {
        blogImageService.update(blogImage);

        return ResultTool.success();
    }

    @PostMapping("/find")
    public JsonResult find(BaseIdReqVO idReqVO) {
        return ResultTool.success(blogImageService.findById(idReqVO.getId()));
    }


    @RequestMapping("/paging")
    public JsonResult paging(@RequestBody PagingReqVO<BlogImage> pagingReqVO){

        PageInfo<BlogImage> iPage= blogImageService.paging(pagingReqVO);

        return ResultTool.success(iPage);
    }
}

